/*************************************************************************
  > File Name: comm.h
  > Author: wusihai
  > Mail: wusihai18@gmail.com 
  > Created Time: Sat Jul 13 10:21:46 2019
 ************************************************************************/

#ifndef COMM_H
#define COMM_H
#include <time.h>
#include "slavertm.h"
//MPI参数
int process_size,my_rank,col_rank,row_rank;
int dims[3];
int nbrs[6];
int x_rank,y_rank,z_rank;
int tag; int ret;
MPI_Status status;
MPI_Request reqs[12];

#define X0 0
#define X1 1
#define Y0 2
#define Y1 3
#define Z0 4
#define Z1 5

//RTM参数
/*外部参数*/
int mgridnumx;
int mgridnumy; int mgridnumz;
int PMLX,PMLY,PMLZ;
int Nsx,Nsy;
int order;
float dt,dh;
float Fm;
int nsnap;
int Nt,Nf;

/*内部参数*/
int SubNx;
int SubNy;
int SubNz;
int DivNx;
int DivNy;
int DivNz;
int wave_len;
int nsgroup,sx,sy,sz,rz;
int nsstart,nsstop;
int it;
/*log 文件*/
FILE* flog;
char gptlfile[100];
time_t timep;
struct tm *p;

//模型数据
#define FILELEN 256
char vppath[FILELEN];
float* vpmodel;//Vp速度模型
float* vp_ext;//Vp速度模型
float* vp_sub;
float  Vpmax;
float  Vpconst;

//子波
float* wavelet;
//波场数据	
float* T;
/*正应力Txx三分量*/
float* Txx   ;
/*正应力Tyy三分量*/
float* Tyy   ;
/*正应力Tzz三分量*/
float* Tzz   ;
/*速度Vx*/
float* Vx   ;
/*速度Vy*/
float* Vy   ;
/*速度Vz*/
float* Vz   ;

//外推波场
float* extrapT   ;
/*正应力Txx三分量*/
float* extrapTxx   ;
/*正应力Tyy三分量*/
float* extrapTyy   ;
/*正应力Tzz三分量*/
float* extrapTzz   ;
/*速度Vextrapx*/
float* extrapVx   ;
/*速度Vy*/
float* extrapVy   ;
/*速度Vz*/
float* extrapVz   ;

//通信buffer
float*  sendX0;
float*  recvX0;
float*  sendY0;
float*  recvY0;
float*  sendZ0;
float*  recvZ0;

float *P1,*P2,*P3,*P4,*P5,*P6; //用于通信

//IO buffer
float* iobufferX0V;
float* iobufferY0V;
float* iobufferZ0V;
float* iobufferX0T;
float* iobufferY0T;
float* iobufferZ0T;


//波场记录
float *recordVz  ;//Vz 分量

//kernel 参数
rtm_slave_parameter parameter;
rtm_slave_parameter parameter_extrap;

rtm_slave_merge parameter_merge;

rtm_slave_image parameter_image;
rtm_slave_image parameter_simage;
rtm_slave_iopack parameter_iopack;
rtm_slave_mpipack parameter_mpipack;
//计算区域
int stX;
int endX;
int stY;
int endY;
int stZ;
int endZ;


//成像数据
float *Total_image,*image,*shot_energy;

unsigned long _totalBytes;
//索引宏
#define v3d(ix,iy,iz)       ix*mgridnumy*mgridnumz+iy*mgridnumz+iz
#define v3d_ext(ix,iy,iz)   ix*(mgridnumy+2*PMLY)*(mgridnumz+2*PMLZ)+iy*(mgridnumz+2*PMLZ)+iz
#define n3d(ix,iy,iz)       ix*DivNy*DivNz+iy*DivNz+iz
#define n3d_ext(ix,iy,iz)   ix*SubNy*SubNz+iy*SubNz+iz

#define n3dY(ix,iy,iz)       ix*5*DivNz+iy*DivNz+iz
#define n3dZ(ix,iy,iz)       ix*DivNy*5+iy*5+iz
#endif
